/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Login.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import stti.model.ServicioSeguridad;
import stti.model.SesionSTTI;

/**
 *
 * @author stti
 */
public class Login extends Action{
    
    public ActionForward execute(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
    {
                try
                {
                    String user =request.getParameter("user");
                    String password = request.getParameter("password");

                    ServicioSeguridad serv = new ServicioSeguridad();
                    SesionSTTI sesion = serv.loginCliente(user, password);
                            
                    request.getSession(false).setAttribute("sesionSTTI",sesion);
                    if(sesion.existe())
                    {    
                    System.out.println("Login as: " + sesion.getCliente().getNombre());
                    return mapping.findForward("Principal");
                    }
                    else
                    {
                        return mapping.findForward("Index");
                    }
                }
                catch (Exception e)
                {
                    return mapping.findForward("Index");
                }
                
    }
    
}
